#include "func.h"

void insert(link *head)
{

    printf("\033c");//清屏
    int num;
    char ch[2];
    link *tmp = head;
    while (1)
    {
here:
        while (tmp->next != NULL) //头插法遍历到最后一个节点
        {
            tmp = tmp->next;
        }
        link *node = (link *)malloc(sizeof(link));
        memset(node, 0, sizeof(link));
        node->next = NULL;
        printf("请输入要添加的联系人编号:");
        scanf("%d", &node->p.id);
        printf("请输入要添加的联系人名字:");
        scanf("%s", node->p.name);
        printf("请输入要添加的联系人年龄:");
        scanf("%d", &node->p.age);
        printf("请输入要添加的联系人电话:");
        scanf("%s", node->p.tel);
        printf("请输入要添加的联系人地址:");
        scanf("%s", node->p.addr);

        tmp->next = node; //链接节点
        node->prev = tmp;
        printf("添加成功！是否继续添加联系人?(y/n): ");
        scanf("%s", ch);
        if (my_strcmp(ch, "Y") == 0 || my_strcmp(ch, "y") == 0)
        {
            goto here;
        }
        else
        {
            break;
        }
    }
}